using System;
using System.Collections.Generic;
using System.Text;
using RideMe.Core.Properties;
using System.IO;
using System.Diagnostics;

namespace RideMe.Core
{
    public class GeneratorProcess : RubyProcess 
    {

        public GeneratorProcess()
        {
        }

        /// <summary>
        /// Generates the specified Rails entity.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="arguments">The arguments.</param>
        public void Generate(string entityType, string arguments)
        {
            RunCommand(GetGeneratorCommandString(entityType, arguments), true);
        }

        /// <summary>
        /// Destroys the specified Rails entity.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="arguments">The arguments.</param>
        public void Destroy(string entityType, string arguments)
        {
          RunCommand(GetDestroyCommandString(entityType, arguments), true);
        }

        /// <summary>
        /// Gets the generator command string.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        private string GetGeneratorCommandString(string commandName, string arguments)
        {
            // Example C:\RideMe\RailsTest\script\generate commandname arguments
            return string.Format(@"'{0}' {1} {2}", Resources.GeneratorPath, commandName, arguments);
        }

        /// <summary>
        /// Gets the destory command string.
        /// </summary>
        /// <param name="generator">The generator.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        private string GetDestroyCommandString(string generator, string arguments)
        {
            // Example C:\ruby\bin\ruby.exe C:\RideMe\RailsTest\script\destroy controller arguments
            return string.Format(@"'{0}' {1} {2}", Resources.DestroyPath, generator, arguments);
        }

    }
}
